package com.yeyks.controller;

import com.yeyks.model.Ajax.AjaxResponseBody;
import com.yeyks.model.em.ResponseStatus;
import com.yeyks.util.JssdkUtility;
import com.yeyks.model.Ajax.AjaxResponseBody;
import com.yeyks.model.em.ResponseStatus;
import com.yeyks.util.JssdkUtility;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("/ajax/wechat")
public class WechatController {

    @ApiIgnore
    @RequestMapping(value = "/getJsapiTicket", method = RequestMethod.POST)
    public ResponseEntity<?> getJsapiTicket(
            @RequestParam(name = "url", defaultValue = "false", required = true) String url
    ) {
        AjaxResponseBody response = new AjaxResponseBody();

        Object jsapiTicket = JssdkUtility.sign(JssdkUtility.getJsapiTicket(), url);

        response.setBody(jsapiTicket);
        response.setCode(ResponseStatus.RS_SUCCESS.getCode());
        response.setMsg(ResponseStatus.RS_SUCCESS.getMsg());
        return ResponseEntity.ok(response);
    }
}
